<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <p:tabView id="itbiTabView" dynamic="true" activeIndex="#{managerItbi.tabActive}">
                <p:ajax event="tabChange" update=":itbiTabView:listItbiForm, :itbiTabView:itbiForm"/>

                <p:tab title="Histórico Geração">
                    <h:form id="listItbiForm" enctype="multipart/form-data">
                        <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 

                        <div class="container_24 clearfix">

                            <h5 class="title">Dados do Imóvel</h5>
                            <p:outputLabel value="Proprietário" styleClass="grid_3" for="proprietario" />
                            <p:inputText id="proprietario" readonly="true"
                                         styleClass="grid_20" value="#{managerItbi.proprietarios(managerItbi.imovel) eq '' ? 'Proprietário Pendente' : managerItbi.proprietarios(managerItbi.imovel)}"/>
                            <div class="clear"/>

                            <p:outputLabel value="Localização" styleClass="grid_3" for="localizacao" />
                            <p:inputText id="localizacao" readonly="true"
                                         styleClass="grid_11" value="Logradouro #{managerItbi.imovel.enderecoImovel.nomeclog eq null or managerItbi.imovel.enderecoImovel.nomeclog eq '' ? managerItbi.imovel.enderecoImovel.logradouro : managerItbi.imovel.enderecoImovel.nomeclog}, Nº #{managerItbi.imovel.enderecoImovel.numero}"/>

                            <p:outputLabel value="Bairro" styleClass="grid_2 alpha" for="bairro" />
                            <p:inputText id="bairro" readonly="true"
                                         styleClass="grid_7" value="Logradouro #{managerItbi.imovel.enderecoImovel.bairro}"/>

                        </div>
                        <br/>

                        <p:dataTable var="itbi" value="#{managerItbi.itbis}" id="itbiDataTable"
                                     rows="5" paginator="true" lazy="true" resizableColumns="true"
                                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                     currentPageReportTemplate="{currentPage} de {totalPages}"
                                     paginatorPosition="bottom" emptyMessage="Nenhum registro">
                            <p:column headerText="Ação" width="90">
                                <p:commandButton update=":itbiTabView" title="Visualizar"
                                                 icon="ui-icon-zoomin" actionListener="#{managerItbi.tabVisualizacao()}">
                                    <f:setPropertyActionListener target="#{managerItbi.itbi}" value="#{itbi}" />
                                    <p:resetInput target=":itbiTabView:itbiForm"/>
                                </p:commandButton>
                                <p:commandButton update="@form" title="Alterar Vencimento"
                                                 oncomplete="dlgVencimento.show()" 
                                                 icon="ui-icon ui-icon-calendar"
                                                 disabled="#{itbi.pago}">
                                    <f:setPropertyActionListener target="#{managerItbi.itbi}" value="#{itbi}" />
                                </p:commandButton>
                                <p:commandButton update="@form" title="Excluir"
                                                 oncomplete="dlgRemover.show()"
                                                 icon="ui-icon-trash"
                                                 disabled="#{itbi.pago}">
                                    <f:setPropertyActionListener target="#{managerItbi.itbiRemocao}" value="#{itbi}" />
                                </p:commandButton>
                            </p:column>
                            <p:column headerText="Geração" width="75">
                                <h:outputText value="#{itbi.dataGeracao}">
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Contribuinte" styleClass="singleLine">
                                <h:outputText value="#{itbi.proprietario.nome}"/>
                            </p:column>
                            <p:column headerText="Transmissão" width="120">
                                <h:outputText value="#{itbi.tipoTransmissao.nome}"/>
                            </p:column>
                            <p:column headerText="Financiamento" width="140">
                                <h:outputText value="#{itbi.tipoFinanciamento.nome}"/>
                            </p:column>
                            <p:column headerText="R$" width="80">
                                <h:outputText value="#{itbi.valor}">
                                    <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="Pago" width="40">
                                #{itbi.pago eq true ? 'pago' : '-'}
                            </p:column>
                            <p:column headerText="Pagamento" width="75">
                                <h:outputText value="#{itbi.dataPagamento}">
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                        </p:dataTable>

                        <p:dialog id="dlgRemover" header="Confirmação de remoção" widgetVar="dlgRemover" modal="true" 
                                  height="80" closable="false" resizable="false" closeOnEscape="true">
                            <h:outputText value="Tem certeza que deseja remover este registro ?" />
                            <div class="buttonAction">
                                <p:commandButton value="Sim"
                                                 actionListener="#{managerItbi.remover()}"
                                                 update="@form"
                                                 icon="ui-icon-check"/>
                                <p:commandButton value="Não" icon="ui-icon-close"
                                                 oncomplete="dlg.hide()" />
                            </div>
                        </p:dialog>

                        <p:dialog id="dlgVencimento" widgetVar="dlgVencimento" modal="true" header="Trocar Vencimento"
                                  height="100" width="470" closable="true" resizable="false" closeOnEscape="true">
                            <p:panel id="dadaosPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix">
                                <p:outputLabel value="Data Vencimento: " styleClass="grid_9" for="dataVencimento" />
                                <p:calendar value="#{managerItbi.itbi.dataVencimento}" 
                                            id="dataVencimento"
                                            showOn="both" 
                                            locale="pt"
                                            navigator="true"
                                            pattern="dd/MM/yyyy"
                                            styleClass="grid_8"/>
                                <div class="clear"/>
                            </p:panel>
                            <div class="buttonAction">
                                <p:commandButton
                                    value="Gerar" 
                                    update="@form"
                                    ajax="true"
                                    actionListener="#{managerItbi.gerarItbi()}"
                                    icon="ui-icon-check" />
                            </div>
                        </p:dialog>
                    </h:form>
                </p:tab>

                <p:tab title="Gerar Guia">
                    <h:form id="itbiForm" enctype="multipart/form-data">
                        <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 

                        <p:panel id="dadaosPanel" style="background: none; border: none;" 
                                 styleClass="container_24 clearfix">
                            <h5 class="title">ITBI</h5>
                            <p:outputLabel value="Inscrição Imóvel" styleClass="grid_4" for="maskinscricao" />
                            <p:inputMask mask="?99.99.999.9999.99" id="maskinscricao" readonly="true"
                                         styleClass="grid_4"  value="#{managerItbi.inscCadastral}"/>

                            <p:outputLabel value="Contribuinte" styleClass="grid_4" for="contribuinte" />
                            <p:inputText id="contribuinte" readonly="true"
                                         styleClass="grid_11"  value="#{managerItbi.itbi.proprietario.nome}"/>

                            <p:outputLabel value="Tipo Transmissão" styleClass="grid_4" for="tipoTransSelectOneMenu" />
                            <p:selectOneMenu  id="tipoTransSelectOneMenu"
                                              style="width: 370px !important; margin-bottom: 5px !important"  
                                              styleClass="grid_4" value="#{managerItbi.itbi.tipoTransmissao}"
                                              rendered="#{!managerItbi.visualizacao}">
                                <f:selectItems value="#{managerItbi.tipoTransmissoes}"/>
                            </p:selectOneMenu>
                            <p:inputText id="tipoTransInputText" readonly="true"
                                         styleClass="grid_4"
                                         rendered="#{managerItbi.visualizacao}"
                                         value="#{managerItbi.itbi.tipoTransmissao.nome}"/>


                            <p:outputLabel value="Tipo Financiamento" styleClass="grid_4" for="tipoFinancSelectOneMenu" />
                            <p:selectOneMenu  id="tipoFinancSelectOneMenu"
                                              rendered="#{!managerItbi.visualizacao}"
                                              style="width: 250px !important; margin-bottom: 5px !important"  
                                              styleClass="grid_4" value="#{managerItbi.itbi.tipoFinanciamento}">

                                <f:selectItems value="#{managerItbi.tipoFinanciamentos}"/>
                                <p:ajax event="change" update=":itbiTabView:itbiForm:aliquota" listener="#{managerItbi.vlrAliquota()}" />
                            </p:selectOneMenu>
                            <p:inputText id="tipoFinanInputText" readonly="true"
                                         styleClass="grid_4"
                                         rendered="#{managerItbi.visualizacao}"
                                         value="#{managerItbi.itbi.tipoFinanciamento.nome}"/>
                            <div class="clear"/> 

                            <p:outputLabel value="Data Vencimento: " styleClass="grid_4" for="dataVencimento" />
                            <p:calendar value="#{managerItbi.itbi.dataVencimento}" 
                                        id="dataVencimento"
                                        showOn="both" 
                                        locale="pt"
                                        navigator="true"
                                        pattern="dd/MM/yyyy"
                                        readonly="#{managerItbi.visualizacao}"
                                        styleClass="grid_4"
                                        rendered="#{!managerItbi.visualizacao}"
                                        required="true"  />
                            <p:inputText id="dataVencimentoInputText" value="#{managerItbi.itbi.dataVencimento}"
                                         readonly="true"
                                         styleClass="grid_4"
                                         rendered="#{managerItbi.visualizacao}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </p:inputText>
                            <div class="clear"/> 
                            <br/>

                            <h5 class="title">Dados do Cálculo</h5>
                            <p:outputLabel value="UFMP" styleClass="grid_4" for="ufmp" />
                            <p:inputText id="ufmp" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.ufmp}"/>
                            <div class="clear"/> 

                            <p:outputLabel value="Área do Terreno (m²)" styleClass="grid_4" for="m2AreaTerreno" />
                            <p:inputText id="m2AreaTerreno" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.m2AreaTerreno}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <p:outputLabel value="Valor m² Terreno (UFMP)" styleClass="grid_5" for="vlrM2Terreno" />
                            <p:inputText id="vlrM2Terreno" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.vlrM2UfmpTerreno}">     
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <p:outputLabel value="Valor do Terreno (R$)" styleClass="grid_5" for="vlrTerreno" />
                            <p:inputText id="vlrTerreno"  readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.vlrTerreno}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <div class="clear"/>

                            <br/>
                            <p:outputLabel value="Fator Depreciação" styleClass="grid_4" for="fatorDepreciacao" />
                            <p:inputText id="fatorDepreciacao"  required="true" readonly="#{managerItbi.visualizacao}"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.fatorDepreciacaoEdificacao}"
                                         onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );"
                                         >    
                                <p:ajax event="change" listener="#{managerItbi.vlrEdificacao()}" update="vlrEdificacao, vlrImovel, vlrBoleto"/>
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <div class="clear"/>

                            <p:outputLabel value="Área Edificada (m²)" styleClass="grid_4" for="m2AreaEdificacao" />
                            <p:inputText id="m2AreaEdificacao" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.m2AreaEdificacao}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <p:outputLabel value="Valor m² Edificação (R$)" styleClass="grid_5" for="vlrM2Edificacao" />
                            <p:inputText id="vlrM2Edificacao" required="true" readonly="#{managerItbi.visualizacao}"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.vlrM2ReaisEdificacao}"
                                         onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );"
                                         >    
                                <p:ajax event="change" listener="#{managerItbi.vlrEdificacao()}" update="vlrEdificacao, vlrImovel, vlrBoleto"/>
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>

                            <p:outputLabel value="Valor da Edificação (R$)" styleClass="grid_5" for="vlrEdificacao" />
                            <p:inputText id="vlrEdificacao" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.vlrEdificacao}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <div class="clear"/>
                            <br/>

                            <p:outputLabel value="Valor Imóvel (R$)" styleClass="grid_4" style="font-weight: bold;" for="vlrImovel" />
                            <p:inputText id="vlrImovel" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.vlrImovel}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>
                            <p:outputLabel value="Alíquota" styleClass="grid_5" style="font-weight: bold;" for="aliquota" />
                            <p:inputText id="aliquota" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.aliquota}">
                                <f:convertNumber pattern="#,###,##0.0000" locale="pt,BR"/>
                            </p:inputText>
                            <p:outputLabel value="Valor a Pagar (R$)" styleClass="grid_5" style="font-weight: bold;" for="vlrBoleto" />
                            <p:inputText id="vlrBoleto" readonly="true"
                                         styleClass="grid_3"  value="#{managerItbi.itbi.valor}">
                                <f:convertNumber pattern="#,###,##0.00" locale="pt,BR"/>
                            </p:inputText>


                        </p:panel>
                        <br/>
                        <div class="buttonAction">
                            <p:commandButton
                                value="Gerar" 
                                update="@form"
                                ajax="true"
                                rendered="#{!managerItbi.visualizacao}"
                                actionListener="#{managerItbi.gerarItbi()}"
                                icon="ui-icon-check" />
                            <p:commandButton value="Imprimir"
                                             actionListener="#{managerItbi.boleto()}"
                                             update="@form"
                                             ajax="false"
                                             rendered="#{managerItbi.visualizacao}"
                                             onclick="this.form.target='_blank'"
                                             icon="ui-icon-check"/>
                            <p:commandButton
                                value="Novo" 
                                update="@form"
                                ajax="true"
                                rendered="#{managerItbi.visualizacao}"
                                actionListener="#{managerItbi.initItbi()}"
                                icon="ui-icon-check">
                                <p:resetInput target=":itbiTabView:itbiForm"/>
                            </p:commandButton>
                        </div>

                    </h:form>

                </p:tab>

            </p:tabView>
        </ui:define>
    </ui:composition>
</html>

